package org.springframework.prospring.ticket.service.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.prospring.ticket.dao.UserDAO;
import org.springframework.prospring.ticket.service.UserManager;
import org.springframework.prospring.ticket.domain.user.User;


public class UserManagerImpl implements UserManager {
    private static Log log = LogFactory.getLog(UserManagerImpl.class);
    private UserDAO dao;

    public UserManagerImpl() {
        super();
        if (log.isDebugEnabled()) {
            log.debug("in UserManagerImpl Constructor");
        }
    }

    public void setUserDAO(UserDAO dao) {
        if (log.isDebugEnabled()) {
            log.debug("setting UserDAO: " + dao);
        }

        this.dao = dao;
    }

    public List getUsers() {
        if (log.isDebugEnabled()) {
            log.debug("getting Users: ");
        }
        return dao.getUsers();
    }

    public User findUser(Long userId) {
        if (log.isDebugEnabled()) {
            log.debug("getting User id: "+userId);
        }
        User user = dao.findUser(userId);

        if (user == null) {
            log.warn("UserId '" + userId + "' not found in database.");
        }

        return user;
    }

    public User saveUser(User user) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("saving User: " + user);
        }

        dao.saveUser(user);

        return user;
    }

    public void removeUser(String userId) {
        dao.removeUser(Long.valueOf(userId));
    }

    public User checkUser(String nickname, String password){
        return dao.checkUser(nickname, password);        
    }


}
